<?php
declare (strict_types = 1);

namespace app\controller;


use think\facade\Db;
use think\facade\View;


class Inews extends Common
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $cid = input("get.cid");
        if($cid){
            $where["cate_id"] = $cid;
        }
        $where["status"] =1;
        $where["model_id"] =5;


        if(!isset($where)){
            $where = 1;
        }

        $list = \app\common\model\Content::with("user")
            ->where($where)
            ->order("top DESC,recommend DESC,id DESC")
            ->paginate([
                'query'=> $this->params,
            ]);

        $temp = $list->items();
        foreach ($temp as $k => $v){
            //更新文章的展现量
            update_hits($v["id"]);
            $d =  str_replace("\\\\\\","",$v["imgs"]);
            $temp[$k]["imgs"] =json_decode($d,true);
        }




        View::assign("list",$list);
        View::assign("temp",$temp);

        View::assign("title","闲言碎语");
        return  view();
    }

    //微资讯详情
    public function detail()
    {
        $id = input("get.id");
        $content = \app\common\model\Content::find($id);
        $list = \app\common\model\News::with(["user"])->where("status",1)
            ->where("contentid",$content["id"])
            ->find();

        View::assign("v",$list);
        View::assign("res",$list);
        View::assign("title","闲言碎语");
        return  view();
    }


}
